<?php
class order_model extends jqxGrid_CI_Model {

    function __construct()
    {
        parent::__construct();
        
    }
    function get($ID=""){
        $query = $this->db->query("
            SELECT dtb_orders.*,dtb_customer.CustomerName,dtb_product.ProductName
                ,dtb_package.PackageName
                ,dtb_product.ProductID,dtb_order_details.UnitPrice,dtb_order_details.Quantity,dtb_order_details.Discount
            FROM dtb_orders
                INNER JOIN dtb_order_details ON ( dtb_orders.ID = dtb_order_details.OrderID )
                LEFT JOIN dtb_product ON ( dtb_order_details.ProductID = dtb_product.ProductID )
                LEFT JOIN dtb_package ON ( dtb_order_details.PackageID = dtb_package.ID )
                LEFT JOIN dtb_customer ON ( dtb_orders.CustomerID = dtb_customer.CustomerID )
            WHERE dtb_orders.ID = '$ID'
        ");
        return $query->result();
    }
    function binding(){
        $strQuery="
            SELECT SQL_CALC_FOUND_ROWS `dtb_orders`.*
            FROM `dtb_orders`
                
            ";
        $strWhere="
            WHERE  true
            ";
        if($_SESSION["ADP"][CCTRL]["display"]==0){
            $strWhere.=" AND `dtb_orders`.`Delete` IS NULL";
        }elseif($_SESSION["ADP"][CCTRL]["display"]==-1){
            $strWhere.=" AND `dtb_orders`.`Delete` IS NOT NULL";
        }
        $strOrderBy="Order By dtb_orders.`Insert` DESC ";
        $strGroupBy="";
        $config=array(
            "strQuery"=>$strQuery,
            "strWhere"=>$strWhere,
            "strOrderBy"=>$strOrderBy,
            "strGroupBy"=>$strGroupBy,
            "usingLimit"=>true,
            "fields"=>array(
            ),
            "datefields"=>array()
        );
        $this->init($config);
        return $this->jqxBinding();
    }
    function binding_order_tour(){
        $strQuery="
            SELECT SQL_CALC_FOUND_ROWS `tbl_order_tour`.*,tbl_tour.Title,tbl_tour.UnitPrice as Monney
            FROM `tbl_order_tour`
                INNER JOIN `tbl_tour` ON (tbl_order_tour.TourID=tbl_tour.ID)
            ";
        $strWhere="
            WHERE  true
            ";
        if($_SESSION["ADP"][CCTRL]["display"]==0){
            $strWhere.=" AND `tbl_order_tour`.`Delete` IS NULL";
        }elseif($_SESSION["ADP"][CCTRL]["display"]==-1){
            $strWhere.=" AND `tbl_order_tour`.`Delete` IS NOT NULL";
        }
        $strOrderBy="Order By tbl_order_tour.`Insert` DESC ";
        $strGroupBy="";
        $config=array(
            "strQuery"=>$strQuery,
            "strWhere"=>$strWhere,
            "strOrderBy"=>$strOrderBy,
            "strGroupBy"=>$strGroupBy,
            "usingLimit"=>true,
            "fields"=>array(
                "Monney"=>"tbl_tour.UnitPrice",
                "Status"=>"tbl_order_tour.Status",
                "Insert"=>"tbl_order_tour.Insert",
                "Update"=>"tbl_order_tour.Update",
                "Delete"=>"tbl_order_tour.Delete"
            ),
            "datefields"=>array()
        );
        $this->init($config);
        return $this->jqxBinding();
    }
}
?>
